(function($){
	$.extend($.fn,{
		popDiv:function(options){
			var opts=$.extend($.fn.popDiv.Defaults,options);
			var zzNewDiv=$("<div class='zz_box'></div>");
			var docWid=$(document).width(),
				docHei=$(document).height();
			var winWid=$(window).width(),
				winHei=$(window).height();
			var screenWid=window.screen.width;
			var isIE=false;
			isIE=$.browser.msie&&$.browser.version=="6.0";
			//alert(isIE);
			var tcDiv=$("#"+opts.tcID),
				tcDivWid=tcDiv.width(),
				tcDivHei=tcDiv.height();
			var tcLeft,tcTop;
			var zzDiv=$("div.zz_box"),
				zzWid=docWid,
				zzHei=docHei;
			var tcClose=$(".tc_close");
			function getPosition(){
				tcLeft=(winWid-tcDivWid)/2;
				if(isIE){
					tcTop=(winHei-tcDivHei)/2+$(window).scrollTop();
				}else{
					tcTop=(winHei-tcDivHei)/2;
				}	
			}
			function showDiv(){
				if(opts.noResize){
					$("html").css({
						overflow:"hidden"	
					});	
				}
				showZZ();
				showTC();
			}
			
			function showZZ(){
				if(opts.isZZ){
					if(zzDiv.length>0){
						zzDiv.css({
							width:zzWid+"px",
							height:zzHei+"px",
							position:"absolute",
							display:"block",
							opacity:0
						});	
						if(opts.noResize){
							
							zzDiv.css({
								width:screenWid+"px"
							});	
							
						}
						if(opts.isAnimated){
							zzDiv.fadeTo(opts.speed,opts.opacity);
						}else{
							zzDiv.css({opacity:opts.opacity});	
						}	
					}else{
						$("body").append(zzNewDiv);
						zzNewDiv.css({
							width:zzWid+"px",
							height:zzHei+"px",
							position:"absolute",
							display:"block",
							opacity:0
						});
						if(opts.noResize){
							
							zzNewDiv.css({
								width:screenWid+"px"
							});	
							
						}
						if(opts.isAnimated){
							zzNewDiv.fadeTo(opts.speed,opts.opacity);
						}else{
							zzNewDiv.css({opacity:opts.opacity});	
						}
					}
				}
			}
			
			$(window).scroll(function(){
				if(isIE){
					getPosition();
					tcDiv.css({
						top:tcTop+"px"
					});	
				}	
			});
			
			tcClose.live("click",function(){
				hideZZ();
				hideTC();
				if(opts.noResize){
					$("html").css({
						overflow:"auto"	
					});	
				}
				opts.moveTC();
			});
			
			function hideZZ(){
				if(opts.isZZ){
					zzDiv=$("div.zz_box");
					if(opts.isAnimated){
						zzDiv.fadeOut(opts.speed);	
					}else{
						zzDiv.css({opacity:0,display:"none"});		
					}
				}
			}
			
			function hideTC(){
				if(opts.isAnimated){
					tcDiv.fadeOut(opts.speed);
				}else{
					tcDiv.css({opacity:0,display:"none"});		
				}	
			}
			
			
			function showTC(){
				if(isIE){
					if(tcDiv.length>0){
						getPosition();
						tcDiv.css({
							position:"absolute",
							left:tcLeft+"px",
							top:tcTop+"px",
							display:"block",
							opacity:0	
						});	
						if(opts.isAnimated){
							tcDiv.fadeTo(opts.speed,1);
						}else{
							tcDiv.css({opacity:1});	
						}	
					}	
				}else{
					if(tcDiv.length>0){
						getPosition();
						tcDiv.css({
							position:"fixed",
							left:tcLeft+"px",
							top:tcTop+"px",
							display:"block",
							opacity:0	
						});	
						if(opts.isAnimated){
							tcDiv.fadeTo(opts.speed,1);
						}else{
							tcDiv.css({opacity:1});		
						}	
					}	
				}	
			}			
			
			showDiv();	
		},
		
		btSwitch:function(options){
			var opts=$.extend({},$.fn.btSwitch.Defaults,options);
			var btWrap=$("div.i_bt_box");	
			var btwLength=btWrap.length;
			//alert(btwLength);
			$.each(btWrap,function(index,value){
				$(value).find("ul.bt_nums").find("li").eq(index).addClass("current").siblings("li").removeClass("current");					   
			});
			var btIndex=1,st;
			btWrap.eq(0).show().addClass("bt_current").siblings("div.i_bt_box").hide().removeClass("bt_current");
			function switchFunc(){
				if(btIndex==btwLength){
					btIndex=0;	
				}
				btWrap.eq(btIndex).show().addClass("bt_current").siblings("div.i_bt_box").hide().removeClass("bt_current");
				btIndex+=1;
				st=setTimeout(switchFunc,opts.speed);
			}
			
			function switchFuncE(){
				if(btIndex==btwLength){
					btIndex=0;	
				}
				btWrap.eq(btIndex).show().addClass("bt_current").siblings("div.i_bt_box").hide().removeClass("bt_current");

			}
			
			st=setTimeout(switchFunc,opts.speed);
			
			var btNums=$("ul.bt_nums");
			var btNumsLi=btNums.find("li");
			btNums.bind("mouseenter",function(){
				clearTimeout(st);								   
			});
			btNums.bind("mouseleave",function(){
				var cBtWrapIndex=btWrap.index($("div.bt_current"));	
				btIndex=cBtWrapIndex+1;
				st=setTimeout(switchFunc,opts.speed);
			});
			btNumsLi.bind("mouseover",function(){
				var curLis=$(this).parent().find("li");
				var curIndex=curLis.index($(this));
				btIndex=curIndex;
				switchFuncE();
			});
		}
		
	});
	$.fn.popDiv.Defaults={
		zzClass:"zz_box", //遮罩样式--可以后append进文档
		tcID:"tcID", //弹出层ID--必须先加载到dom文档
		tcClose:"tc_close",//弹出层关闭样式
		isAnimated:true, //是否允许动画
		speed:400, //动画持续时间
		isZZ:true, //是否允许遮罩层
		opacity:0.5, //遮罩透明度
		noResize:false, //是否禁用滚动条
		moveTC:function(){}
	}
	
	$.fn.btSwitch.Defaults={
		speed:3000	
	}

})(jQuery);